package com.mall.service.impl;

import com.mall.mapper.OrderMapper;
import com.mall.po.Order;
import com.mall.service.OrderService;
import com.mall.util.ColumnEdit;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mahaoqi
 * @ClassName OrderServiceImpl
 * @Description TODO
 * @Date 2021/1/7 11:48
 * @Version 1.0
 **/
@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;
    @Resource
    private ColumnEdit columnEdit;

    /*
     * @Author mahaoqi
     * @Description 添加
     * @Date 2021/1/7 14:05
     * @Param [order]
     * @return java.lang.Boolean
     **/
    @Override
    public Boolean addOrder(Order order) {
        return orderMapper.insertOne(order)>0;
    }

    /*
     * @Author mahaoqi
     * @Description 根据id删除
     * @Date 2021/1/7 14:07
     * @Param [orderid]
     * @return boolean
     **/
    @Override
    public Boolean removeById(Integer orderid) {
        return orderMapper.deleteById(orderid)>0;
    }

    /*
     * @Author mahaoqi
     * @Description 修改
     * @Date 2021/1/7 14:10
     * @Param [order]
     * @return java.lang.Boolean
     **/
    @Override
    public Boolean modifyOrder(Order order) {
        Order findOrder = orderMapper.selectById(order.getOrderid());
        if(findOrder!=null){
            findOrder = (Order)columnEdit.updateObject(order,findOrder);
            return orderMapper.updateOne(findOrder)>0;
        }
        return null;
    }

    /*
     * @Author mahaoqi
     * @Description 查找
     * @Date 2021/1/7 14:36
     * @Param [orderid]
     * @return com.mall.po.Order
     **/
    @Override
    public Order findByid(Integer orderid) {
        return orderMapper.selectById(orderid);
    }

    /*
     * @Author mahaoqi
     * @Description 分页 
     * @Date 2021/1/7 14:58
     * @Param [i, limit]
     * @return java.util.List<com.mall.po.Order>
     **/
    @Override
    public List<Order> findList(int page, Integer limit) {
        return orderMapper.selectList(page,limit);
    }

    @Override
    public Integer findCount() {
        return orderMapper.selectCount();
    }

    @Override
    public boolean removeBatch(Integer[] orderids) {
        return orderMapper.deleteBatch(orderids)>0;
    }
}
